﻿
  

@{
	Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Demo</title>
	<!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
	<link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">
	@* 导出引入文件 *@
	<title>Layui with XLSX</title>
	<!-- 引入Layui的CSS -->
	@* <link rel="stylesheet" href="path/to/layui.css"> *@
	<!-- 引入XLSX库的CDN -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
	<title>Layui 导入按钮示例</title>
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/layui/2.6.8/css/layui.css">
	<script src="https://cdnjs.cloudflare.com/ajax/libs/layui/2.6.8/layui.js"></script>
</head>
<body>
	<form class="layui-form" action="">
		<div class="layui-form-item">
			<div class="layui-form-item">

				 <div class="layui-inline">
                    <label class="layui-form-label">权限编码</label>
                    <div class="layui-input-block">
                        <input type="text" id="permissionCoding" placeholder="请输入" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">权限名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="permissionName" placeholder="请输入" class="layui-input">
                    </div>

                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">权限类型</label>
                    <div class="layui-input-block">
                        <select name="interest" lay-filter="testSelect1" id="permissionTypeId">
                            <option value="0" selected>请选择</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select id="permissionState" lay-filter="testSelect2">
                            <option value="0">请选择</option>
                            <option value="1">有效</option>
                            <option value="2">无效</option>
                        </select>
                    </div>
                </div>
           
				<button type="button" class="layui-btn layui-bg-bluee">打印</button>
				<button type="button" class="layui-btn layui-bg-blue">导出</button>
				<button type="button" class="layui-btn layui-bg-red" lay-on="test-iframe-curl" onclick="AddPermission()">+新增</button>
			</div>
		</div>

		<table class="layui-table">
			<thead>
				<tr>
					<td>序号</td>
					<td>订单编码</td>
					<td>订单名称</td>
					<td>订单类型</td>
					<td>所属项目</td>
					<td>客户</td>
					<td>创建时间</td>
					<td>状态</td>
					<td>操作</td>
				</tr>
			</thead>
			<tbody></tbody>
		</table>
		<div id="demo-laypage-all"></div>
	</form>


	<script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
	<script>

		layui.use(['form', 'laydate', 'util'], function () {
			var form = layui.form
			var upload = layui.upload;
			var layer = layui.layer;
			var laypage = layui.laypage;
			var $ = layui.$;
			var layer = layui.layer;
			var util = layui.util;


			$(function () {
				ShowWorkCenter();
			})

			//打印

			form.on('submit(demo1)', function (d) {

			})
				

			



			//销售订单列表
			function ShowWorkCenter() {
				$.ajax({
					url: '@ViewBag.RBACWrite' + "/api/Sale/showSale",
					data: JSON.stringify({}),
					type: "post",
					dataType: "json",
					contentType: "application/json",
					success: res => {
						console.log(res);
						$("tbody").empty(); // 清空tbody内容
						if (res.data != null) {
							$.each(res.data, function () {
								$("tbody").append(`
										<tr>
										  <td>${this.salesId}</td>
										  <td>${this.salesNo}</td>
										  <td>${this.salesName}</td>
										  <td>${this.salesType}</td>
										  <td>${this.salesItem}</td>
										  <td>${this.salesPro}</td>
										  <td>${new Date(this.salesSta).toLocaleDateString()}</td>
										  <td>${this.smark}</td>
										  <td><button type="button" class="layui-btn layui-btn-xs" onclick="GetWorkCenter(${this.salesId})">编辑</button>
										  <button type="button" class="layui-btn layui-btn-danger layui-btn-xs" onclick="DeleteWorkCenter(${this.salesId})">删除</button>
										 </td>
										 </tr>
										 `);
							});
						}
					}
				});
			}
		});

		

	

		//导出
		function exportTableToExcel() {
			var table = document.querySelector("table.layui-table tbody");
			var ws = XLSX.utils.table_to_sheet(table);
			var wb = XLSX.utils.book_new();
			XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
			XLSX.writeFile(wb, "工作中心列表.xlsx");
		}

		document.querySelector(".layui-btn.layui-bg-blue").addEventListener("click", exportTableToExcel);



		//删除工作中心
		function DeleteWorkCenter(salesId) {
			// 显示确认对话框
			if (confirm('您确定要删除这个订单吗？')) {
				var data = {
					salesId: salesId
				};
				$.ajax({
					url: '@ViewBag.RBACWrite' + "/api/Sale/deleteSale",
					data: JSON.stringify(data),
					type: "DELETE",
					dataType: "json",
					contentType: "application/json",
					success: res => {
						if (res.code == 0) {
							layer.msg('删除成功');
							location.reload();
						} else {
							layer.msg('删除失败');
						}
					}
				});
			} else {
				// 用户点击了取消按钮，不执行删除操作
				layer.msg('已取消删除');
			}
		}
	</script>


	<script>

		//权限添加
		function AddPermission() {
			location.href = "/Sale/AddSale"
		}

		function GetWorkCenter(salesId) {
			localStorage.setItem("salesId", salesId)
			location.href = '/Sale/UpdateSale';
		}


	</script>

</body>
</html>
